package com.ruoyi.oss.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

@Getter
@Setter
@ToString
@AllArgsConstructor
@RequiredArgsConstructor
@Entity
@Table(name = "sys_oss_download_records")
@TableName(value = "sys_oss_download_records")
public class SysOssDownloadRecords implements Serializable {

    private static final long serialVersionUID = -1498536445387299112L;

    /**
     * 主键
     */
    @Id
    @TableId(value = "id")
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 文件下载记录的id
     */
    @TableField(value = "sys_oss_id")
    @Column(name = "sys_oss_id")
    private Long sysOssId;

    /**
     * 下载时间
     */
    @TableField(value = "download_time")
    @Column(name = "download_time")
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date downloadTime;

    /**
     * 下载用户信息
     */
    @TableField(value = "user_id")
    @Column(name = "user_id")
    private Long userId;

    /**
     * 下载文件时的id地址
     */
    @TableField(value = "ip_address")
    @Column(name = "ip_address")
    private String ipAddress;

    /**
     * 用户下载时的User-Agent信息
     */
    @TableField(value = "user_agent")
    @Column(name = "user_agent")
    private String userAgent;


    @Override
    public final boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
        Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
        if (thisEffectiveClass != oEffectiveClass) return false;
        SysOssDownloadRecords that = (SysOssDownloadRecords) o;
        return getId() != null && Objects.equals(getId(), that.getId());
    }

    @Override
    public final int hashCode() {
        return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
    }
}
